package com.xu.finalshell.activation.util;

import com.xu.finalshell.activation.enums.UpgradeVersionEnum;

/**
 * 以下代码仅供学习交流, 不得用于商业用途
 */
public class ActivationUtil {
    public static String newVersionCode(String machineCode, UpgradeVersionEnum upgradeVersionEnum) {
        if (machineCode == null || machineCode.trim().isEmpty() || upgradeVersionEnum == null) {
            throw new IllegalArgumentException("输入参数异常");
        }
        if (UpgradeVersionEnum.ADVANCED.equals(upgradeVersionEnum)) {
            return DigestUtil.keccak384Hex(machineCode + "hSf(78cvVlS5E").substring(12, 28);
        } else if (UpgradeVersionEnum.PROFESSIONAL.equals(upgradeVersionEnum)) {
            return DigestUtil.keccak384Hex(machineCode + "FF3Go(*Xvbb5s2").substring(12, 28);
        } else {
            throw new IllegalArgumentException("暂不支持其它版本");
        }
    }

    public static String oldVersionCode(String machineCode, UpgradeVersionEnum upgradeVersionEnum) {
        if (machineCode == null || machineCode.trim().isEmpty() || upgradeVersionEnum == null) {
            throw new IllegalArgumentException("输入参数异常");
        }
        if (UpgradeVersionEnum.ADVANCED.equals(upgradeVersionEnum)) {
            return DigestUtil.md5Hex("61305" + machineCode + "8552").substring(8, 24);
        } else if (UpgradeVersionEnum.PROFESSIONAL.equals(upgradeVersionEnum)) {
            return DigestUtil.md5Hex("2356" + machineCode + "13593").substring(8, 24);
        } else {
            throw new IllegalArgumentException("暂不支持其它版本");
        }
    }

    public static boolean isNewVersion(String version) {
        return version.compareTo("3.9.6") >= 0;
    }
}
